package utility

import (
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gview"
)

func WriteTplByLayout(r *ghttp.Request, mainTpl string, params ...gview.Params) {
	param := gview.Params{
		"mainTpl": mainTpl,
	}
	// 如果提供了参数，则合并到默认参数中
	if len(params) > 0 {
		for k, v := range params[0] {
			param[k] = v
		}
		params[0] = param
	} else {
		// 如果没有提供参数，则使用默认参数
		params = append(params, param)
	}

	// 设置主模板
	if mainTpl != "" {
		params[0]["mainTpl"] = mainTpl
	}
	r.Response.WriteTpl("layouts/default.html", params...)
}
